Skip to content

Dead PR: loopback.token option.defaultTokenKeys - #1347

Closed
OwenBrotherwood wants to merge 30 commits into
strongloop:masterfrom
OwenBrotherwood:master
Closed

OwenBrotherwood wants to merge 30 commits into
strongloop:masterfrom
OwenBrotherwood:master

Conversation

@OwenBrotherwood

Copy link
Copy Markdown
Contributor

Edit:
Pull request closed #1347 (comment)

Allow full control of which methods and values are used to obtain Access Token.
Requires specific methods and values as option

Example:
Only allow headers as source of Access Token from X-Access-Token and authorization

loopback.token({headers: ['X-Access-Token', 'authorization'], searchDefaultTokenKeys: false })

Signed-off-by: Owen Brotherwood owen@brotherwood.biz

Edit:
#1347 (comment) option name change from options.defaultTokenKeys to options.searchDefaultTokenKeys

@slnode

slnode commented Apr 29, 2015

Copy link
Copy Markdown

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@bajtos

bajtos commented Apr 29, 2015

Copy link
Copy Markdown
Member

@slnode ok to test

@bajtos

bajtos commented Apr 29, 2015

Copy link
Copy Markdown
Member

@OwenBrotherwood Thank you for the pull request.

  1. We use two spaces for indentation, not tab characters.
  2. Can you please add unit-tests to verify that your implementation works correctly and to prevent regressions in the future?

@bajtos bajtos self-assigned this Apr 29, 2015
@OwenBrotherwood

Copy link
Copy Markdown
Contributor Author

@bajtos
Will do: I am not a full time programmer: and at the time I was using vi as it was a small patch but forgot space/tab
I wanted to do unit-tests: I just wanted an excuse to find out how to.

  • Perhaps a link to a unit-test I can use as the base (there must be one for the original routines somewhere) would save me a little time.

Any comments about the option name noConcat ? I couldn't think of a better one at the time

Notes:

Beginners help for test (my first guesses before googling)

@bajtos

bajtos commented Apr 30, 2015

Copy link
Copy Markdown
Member

Any comments about the option name noConcat

Perhaps includeDefaults: false or excludeDefaults: true would be a better name?

Regarding the unit-tests, test/access-token.test.js is the best place where to add the new test. Take a look at "should populate req.token from the query string" for an example. You will need to modify createTestAppAndRequest to accept options for the token middleware.

Let me know how far you get and if there is anything else I can do to help you along the way.

@bajtos bajtos added the blocked label Apr 30, 2015
@OwenBrotherwood

Copy link
Copy Markdown
Contributor Author

@bajtos

@OwenBrotherwood OwenBrotherwood changed the title loopback.token noConcat loopback.token option.defaultTokenKeys Apr 30, 2015
@OwenBrotherwood

Copy link
Copy Markdown
Contributor Author

@bajtos
Take a look
Comments are in #1347 (comment)
1 test made and support for others

I think when everything is ok, it might be nicer to reject this push and I can create a "nicer" push: to many commits for my taste

@OwenBrotherwood

Copy link
Copy Markdown
Contributor Author

@bajtos
On a clone of strongloop/loopback (from today), mocha test/access-token.js gives a lot of fails.

@bajtos

bajtos commented May 4, 2015

Copy link
Copy Markdown
Member

@OwenBrotherwood loopback tests have this ugly quirk that you cannot run a single test file, you must include test/support.js too:

$ mocha test/support.js test/access-token.js

The easiest way to run a subset of unit-tests is to use the -g option:

$ mocha -g AccessToken

I think when everything is ok, it might be nicer to reject this push and I can create a "nicer" push: to many commits for my taste

You can clean up the commit history by running git rebase -i master and then git push -f. But don't worry about that, I can clean it up myself once the patch is ready to be merged.

Comment thread test/access-token.test.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the line length at 80 characters max.

@bajtos

bajtos commented May 4, 2015

Copy link
Copy Markdown
Member

@OwenBrotherwood Please add another test to verify that the default token keys are not added. I.e. send a request that would be authorized with defaultTokenKeys: true, and verify that it returns 401 when defaultTokenKeys: false.

@ritch I feel the option name defaultTokenKeys is not the best one, can you come up with a better name?

Comment thread common/models/access-token.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest a different option name:

searchDefaultTokenKeys: false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I was getting tired of the other name

@OwenBrotherwood

Copy link
Copy Markdown
Contributor Author

@bajtos
As far as I can see, there is a possible problem with the main test:
https://github.com/strongloop/loopback/blob/master/test/access-token.test.js?#L364-L365

  • it only tests the contents of the req and not the validity of the req with referance to the model/user role/ACL/Authentication/Authorization

I now have the same test:
https://github.com/OwenBrotherwood/loopback/blob/eb44d7744dfb855a43d1630b86d7ea4663f42623/test/TEST-loopback-token-searchDefaultTokenKeys.js?#L75-L91

I will now try and make sure that the user's use of a model is allowed by allowing the code to generate 200 or 401 instead of the assert test.

@bajtos

bajtos commented May 7, 2015

Copy link
Copy Markdown
Member

it only tests the contents of the req and not the validity of the req with referance to the model/user role/ACL/Authentication/Authorization

@OwenBrotherwood Just call a different URL path instead of /. Here is an existing test test/access-token.test.js#L284-L298 that expects a 401 response.

Comment thread common/models/access-token.js Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use a simpler check options.searchDefaultTokenKeys !== false. It works well for true, false and undefined, even though it behaves differently for edge cases like null or non-boolean value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will use !== false so that it the same as is currently used for this type of test

@bajtos

bajtos commented May 7, 2015

Copy link
Copy Markdown
Member

@OwenBrotherwood To be honest, I am quite confused about the direction you are taking and don't know what's the best way how I can help you to move forward. Please let me know if there is anything else to answer or explain in addition to my comments above.

@OwenBrotherwood

Copy link
Copy Markdown
Contributor Author

@bajtos
I understand the comment :)
I close this PR will continue to work on my fork.
Why? I use https://gitter.im/strongloop/loopback and all my work in my fork keeps creating "noise" in the right hand panel as I push to my fork.
I use https://gitter.im/strongloop/loopback to watch and learn: maybe others are doing the same and all the OwenBrotherwood push's are basically "noise".
We have tracking on #1326 ie when I am ready to make the final PR, I will @bajtos there (or if I have a problem)

The current status is, there is a reasonably alteration to support options.searchDefaultTokenKeys https://github.com/OwenBrotherwood/loopback/blob/2bef4d861bd70ac823c62cfe4580af598d956d83/common/models/access-token.js?#L171-176
BUT
If someone uses the api wrongly, ie loopback.token({searchDefaultTokenKeys:false),the call to the API will suceed even with the call not making any sense.
The wrong usage should throw an error, and the user is warned: code alteration in the call to the api to support the new option to be friendly to the user.

And of course a tests to ensure that the api loopback.token(options) is tested all the way from the call to the api to what is expected as the result.

@bajtos

bajtos commented May 13, 2015

Copy link
Copy Markdown
Member

We have tracking on #1326 ie when I am ready to make the final PR, I will @bajtos there (or if I have a problem)

OK, thanks for letting me know.

If someone uses the api wrongly, ie loopback.token({searchDefaultTokenKeys:false),the call to the API will suceed even with the call not making any sense.
The wrong usage should throw an error, and the user is warned: code alteration in the call to the api to support the new option to be friendly to the user.

That's a good idea! 👍

@OwenBrotherwood OwenBrotherwood changed the title loopback.token option.defaultTokenKeys Dead PR: loopback.token option.defaultTokenKeys May 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants